#include<iostream>
#include<cstring>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
int a[N];
int n;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> n;
		memset(a, 0, sizeof(a));
		if (n == 1) {
			cout << 1 << endl;
			continue;
		}
		if (n == 2) {
			cout << 2 << " " << 1 << endl;
			continue;
		}
		if (n == 3) {
			cout << "2 1 3" << endl;
			continue;
		}
		if (n == 4) {
			cout << "2 1 4 3" << endl;
			continue;
		}
		int x = n - 3;
		int y = 4;
		if (x & 1) {
			a[1] = 5;
			a[n / 2] = 1;
			a[n / 2 - 1] = 2;
			int k2 = x / 2 - 1;
			int k3 = 2;
			while (k2--) {
				if (y == 5)y++;
				a[k3++] = y++;
			}
			// 			for (int i = 2; i <= x / 2 - 1; i++) {
			// 			    if(y==5)y++;
			// 				a[i] = y++;
			// 			}
			int z = x / 2 + 1;
			int k1 = n;
			int k = n;
			while (z--) {
				if (k1 == 5)k1--;
				a[k - 1] = k1--;
				k--;
			}
		}
		else {
			a[1] = 5;
			a[n / 2] = 2;
			a[n / 2 + 1] = 1;
			for (int i = 2; i <= x / 2; i++) {
				if (y == 5)y++;
				a[i] = y++;
			}
			int z = x / 2;
			int k1 = n;
			int k = n;
			while (z--) {
				if (k1 == 5)k1--;
				a[k - 1] = k1--;
				k--;
			}
		}
		int idx1 = 0;
		int idx2 = 0;
		for (int i = 1; i <= n; i++) {
			if (a[i] == 1) {
				idx1 = i + 1;
				break;
			}
		}
		for (int i = 1; i <= n; i++) {
			if (a[i] == 4) {
				idx2 = i;
				break;
			}
		}
		swap(a[idx1], a[idx2]);
		//swap(a[2],a[n-1]);
		/*if (n >= 5)a[1] = 5;
		else a[1] = n;
		a[2] = 2;
		a[3] = 1;
		int cnt = 4;
		for (int i = 4; i <= n; i++) {
			if (cnt == 3 || cnt == 5) {
				cnt++;
			}
			a[i] = cnt++;
		}*/
		a[n] = 3;
		for (int i = 1; i <= n; i++) {
			cout << a[i] << " ";
		}
		cout << endl;
	}
	return 0;
}